import tornado.web
import tornado.ioloop
from os.path import abspath, join
import sys

sys.path.append(abspath(join(__file__, '../../..')))

if __name__ == '__main__':
    from backend.server.handlers import IndexHandler, GenerateSampleHandler, \
        BaseGenerateHandler, \
        C3Handler, C3ExampleHandler, \
        CHIDHandler, CHIDExampleHandler, \
        AFQMCHandler, AFQMCExampleHandler, \
        PerplexityCalculationHandler, \
        TrueTextPredictionHandler, \
        FixTextHandler
    from backend.server.implement import server_port

    app = tornado.web.Application([
        (r'/', IndexHandler),
        (r'/generate', GenerateSampleHandler),
        (r'/generate/config', BaseGenerateHandler),
        (r'/c3', C3Handler),
        (r'/c3/sample', C3ExampleHandler),
        (r'/chid', CHIDHandler),
        (r'/chid/sample', CHIDExampleHandler),
        (r'/afqmc', AFQMCHandler),
        (r'/afqmc/sample', AFQMCExampleHandler),
        (r'/perplexity', PerplexityCalculationHandler),
        (r'/true_text_prediction', TrueTextPredictionHandler),
        (r'/fix_text', FixTextHandler),
    ])
    # 绑定一个监听端口
    app.listen(server_port)
    tornado.ioloop.IOLoop.current().start()
